class CommentController < ApplicationController

  def list
    @comments=Comment.paginate_by_sql(["select * from comments where  comment_type=? and parent_id=? order by created_at desc",params[:comment_type],params[:parent_id]],:page => params[:page]||1)
    render(:partial=>"comment/list")
  end

  def add
    @comment=Comment.new(params[:comment])
    @comment.ip=request.remote_ip
    @comment.floor=1+Comment.count_by_sql(["select count(id) from comments where comment_type=? and parent_id=?",@comment.comment_type,@comment.parent_id])
    if session[:username]!=nil
      @comment.username=session[:username]
      @comment.userid=session[:userid]
    end
    
    if @comment.save
      @comments=Comment.paginate_by_sql(["select * from comments where  comment_type=? and parent_id=? order by created_at desc",@comment.comment_type,@comment.parent_id],:page => params[:page]||1)
      #render(:partial=>"comment/list",:object=>@comments)
    end
    
  end

  def lock
  end

  def unlock
  end
end
